// pages/mine/orders/index.js
Page({
  data: {
    winHeight: "",//窗口高度
    currentTab: 0, //预设当前项的值
    scrollLeft: 0, //tab标题的滚动条位置
    itemList: [{ text: '全部', id: 1 }, { text: '待付款', id: 2 }, { text: '待分享', id: 3 }, { text: '待发货', id: 4 }, { text: '待收货', id: 5 }, { text: '待评价', id: 6,}],
    ordersList: [1,2,3,4],
    isDisp: false,
    goodsList: [1, 2, 3, 4, 5, 6, 7]
  },
  // 滚动切换标签样式
  switchTab: function (e) {
    this.setData({
      currentTab: e.detail.current
    });
    this.checkCor();
  },
  // 点击标题切换当前页时改变样式
  swichNav: function (e) {
    console.log(e)
    var cur = e.currentTarget.dataset.index;
    console.log(cur)
    if (this.data.currentTaB == cur) { return false; }
    else {
      this.setData({
        currentTab: cur,
      })
    }
  },
  //判断当前滚动超过一屏时，设置tab标题滚动条。
  checkCor: function () {
    if (this.data.currentTab > 2) {
      this.setData({
        scrollLeft: 300
      })
    } else {
      this.setData({
        scrollLeft: 0
      })
    }
  },
  //页面初始加载
  onLoad: function (options) {
    var that = this;
    if (options.orderItem == 'all') {
      that.setData({
        currentTab: 0
      })
    }else {
      var currentTab = parseInt(options.orderItem)
      currentTab = currentTab + 　1
      that.setData({
        currentTab
      })
    }
    
    //  高度自适应
    wx.getSystemInfo({
      success: function (res) {
        var clientHeight = res.windowHeight,
          clientWidth = res.windowWidth,
          rpxR = 750 / clientWidth;
        var calc = clientHeight * rpxR - 180;
        console.log(calc)
        that.setData({
          winHeight: calc
        });
      }
    });
  },
  /**
   * 上拉加载
   */
  scrollHandlerTap: function() {
    console.log("========")
    var goodsList = this.data.goodsList
    for(var i = 0; i < 10; i++) {
      goodsList.push(i)
    }
    this.setData({
      goodsList,
    })
  }
})